<?php
class ZendX_Config {
	static public function factory($file, $section) {
		$suffix      = pathinfo($file, PATHINFO_EXTENSION);
		$suffix      = ($suffix === 'dist')
		? pathinfo(basename($file, ".$suffix"), PATHINFO_EXTENSION)
		: $suffix;
		
		switch (strtolower($suffix)) {
			case 'ini':
				$config = new Zend_Config_Ini($file, $section);
				break;
		
			case 'xml':
				$config = new Zend_Config_Xml($file, $section);
				break;
		
			case 'json':
				$config = new Zend_Config_Json($file, $section);
				break;
		
			case 'yaml':
			case 'yml':
				$config = new Zend_Config_Yaml($file, $section);
				break;
		
			case 'php':
			case 'inc':
				$config = include $file;
				if (!is_array($config)) {
					throw new Zend_Application_Exception('Invalid configuration file provided; PHP file does not return array value');
				}
				return $config;
				break;
		
			default:
				throw new Zend_Application_Exception('Invalid configuration file provided; unknown config type');
		}
		
		return $config;
	}
}